/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Network;

import Burst.AGCH;
import Burst.RACH;
import Frame.Frame;
import Mobile.Mobile;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Javinel
 */
public class Network {
    private int[] unusedSlots;
    private ArrayList<Frame> frames; //trames TDMA générées
    private static int counterFrame; // compteur de trames pour attribution N° trame générée
    private ArrayList<RACH> rachReceived; //demande de communication reçues par le réseau
    private ArrayList<Mobile> mobiles; // mobiles du réseau
    private AGCH nextAGCH; //prochain agch à envoyer à la prochaine trame générée
    private Thread frameGenerator;
    private Thread agchGenerator;
    private int stateThreadAGCHgenerator=1; // controle le thread agch... à 1 ==> thread actif

    public synchronized int getStateThreadAGCHgenerator() {
        return stateThreadAGCHgenerator;
    }

    public void setStateThreadAGCHgenerator(int stateThreadAGCHgenerator) {
        this.stateThreadAGCHgenerator = stateThreadAGCHgenerator;
    }

    public Thread getFrameGenerator() {
        return frameGenerator;
    }

    public void setFrameGenerator(Thread frameGenerator) {
        this.frameGenerator = frameGenerator;
    }

    public Thread getAgchGenerator() {
        return agchGenerator;
    }

    public void setAgchGenerator(Thread agchGenerator) {
        this.agchGenerator = agchGenerator;
    }

    public AGCH getNextAGCH() {
        return nextAGCH;
    }

    public void setNextAGCH(AGCH nextAGCH) {
        this.nextAGCH = nextAGCH;
    }

    public synchronized ArrayList<Mobile> getMobiles() {
        return mobiles;
    }

    public void setMobiles(ArrayList<Mobile> mobiles) {
        this.mobiles = mobiles;
    }

    public int[] getUnusedSlots() {
        return unusedSlots;
    }

    public void setUnusedSlots(int[] unusedSlots) {
        this.unusedSlots = unusedSlots;
    }

    public ArrayList<Frame> getFrames() {
        return frames;
    }

    public void setFrames(ArrayList<Frame> frames) {
        this.frames = frames;
    }

    public static int getCounterFrame() {
        return counterFrame;
    }

    public static void setCounterFrame(int counterFrame) {
        Network.counterFrame = counterFrame;
    }

    public synchronized ArrayList<RACH> getRachReceived() {
        return rachReceived;
    }

    public synchronized void setRachReceived(ArrayList<RACH> rachReceived) {
        this.rachReceived = rachReceived;
    }
    
    
    public Network(){
        this.unusedSlots= new int[8];
        this.mobiles=new ArrayList<Mobile>();
        this.rachReceived=new ArrayList<RACH>();
        this.frameGenerator=new Thread(new ThreadFrameGenerator(this));
        this.agchGenerator=new Thread(new ThreadAGCHGenerator(this));
        this.agchGenerator.start();
    }
    
    public void addRACH(RACH r){
        this.rachReceived.add(r); 
    }
    
    public void addMobile(Mobile m){
        this.mobiles.add(m);
        m.setNetwork(this);
    }
    
    public synchronized Mobile getMobile(int id){
        for(Mobile m:mobiles){
            if(m.getId()==id){
                return m;
            }
        }
        return null;
    }
    
    
    
    public void addMobile(List<Mobile> l){
            this.mobiles=(ArrayList<Mobile>) l;
            for(Mobile m:mobiles){
            
                m.setNetwork(this);
            
            }
    }
    
    public void sendAGCH(){
        
    }
}
